/*
 * Middleware
 * Copyright (C) 2010/11
 * Riccardo Pulvirenti, Giuseppe Ravidà, Andrea Tino
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANDABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses
 */

/*!
 * File: tqueue_manager_proxy.hpp
 */

#ifndef _TQUEUE_MANAGER_PROXY_HPP_
#define _TQUEUE_MANAGER_PROXY_HPP_

#include <iostream>
#include <string>

#include "worker.hpp"
#include "task_descriptor.hpp"
#include "tqueue.hpp"
#include "proxy_exception.hpp"

//-----------------------------------------------------------------------------
// Enum, struct, aliases
namespace middleware {
/*! \struct TProxyConfig
 * \brief Configuration for TQueueManagerProxy.
 *
 * Configuration structure for TQueueManagerProxy.
 */
typedef struct {
	/*!
	 * Pointer to Worker where enqueueing a TaskDescriptor.
	 */
	Worker* ptrto_worker;
} TProxyConfig;
}
//-----------------------------------------------------------------------------
// Class definitions
namespace middleware {
/*! \class TQueueManagerProxy
 * \brief Managing communication between Manager and Worker.
 *
 * This class provides an interface to access the TaskDescriptor queue in the
 * Worker of a peer. It is important to notice that constructor is private
 * in order to let a factory perform instantiation.
 */
class TQueueManagerProxy : public TQueue {
	/*!
	 * To let factory build properly this object, we provide access to every
	 * part of it.
	 */
	friend class TQueueProxyFactory;
public:
	/*!
	 * Destructor
	 */
	~TQueueManagerProxy();
	/*!
	 * Enqueues a TaskDescriptor in the queue stored in the Worker of a peer.
	 * This method is executed locally and does not require network to perform
	 * data exchange.
	 * \param task TaskDescriptor to enqueue.
	 * \exception ProxyException Thrown when Worker encounters problems in
	 * enqueueing the TaskDescriptor.
	 */
	void enqueue(const TaskDescriptor& task) throw(ProxyException);
	/*!
	 * Dequeues a TaskDescriptor from Worker. This is an ORPHAN. This
	 * functionality, despite provided, is not exposed by the Worker. It is
	 * available in the proxy just for future implementation reasons.
	 * \return It is supposed to return the dequeued TaskDescriptor.
	 * \exception ProxyException This exception is supposed to be thrown in
	 * the case of a problem encountered by the Worker when trying to dequeue
	 * the TaskDescriptor.
	 */
	TaskDescriptor dequeue() throw(ProxyException);
private:
	/*!
	 * Privately constructs the object. Default configuration with invalid
	 * manager pointer.
	 */
	TQueueManagerProxy();
	/*!
	 * Privately constructs the object. Assigning configuration.
	 */
	explicit TQueueManagerProxy(TProxyConfig conf);
	/*!
	 * Parameters for proxy.
	 */
	TProxyConfig _config;
}; /* WFQueueManagerProxy */
} /* middleware */

#endif
